
import  { BpmnOption } from './dataType.ts'
import { API_BPMN_ENUM } from '@/api/workflow/bpmnEnum.ts'
import {BpmnEnumDataKey} from '@/utils/constants.ts'
//console.log(data[FieldEnum.NAME]); // 输出 'Alice'
export interface BpmnEnumState {
  bpmnUserTaskCandidateStrategyOptions: BpmnOption[],
  bpmnModelFormTypeOptions: BpmnOption[],
  bpmnModelTypeOptions:BpmnOption[],
  bpmnProcessListenerTypeOptions:BpmnOption[],
  bpmnProcessListenerValueTypeOptions:BpmnOption[],
  initialized: boolean
}
const useBpmnEnumStore = defineStore(
  'bpmn-enum',
  {
    state: (): BpmnEnumState => ({
      bpmnUserTaskCandidateStrategyOptions: [],
      bpmnModelFormTypeOptions: [],
      bpmnModelTypeOptions: [],
      bpmnProcessListenerTypeOptions:[],
      bpmnProcessListenerValueTypeOptions:[],
      initialized: false
    }),

    getters:{
        getBpmnUserTaskCandidateStrategyOptions(): BpmnOption[] {
          return this.bpmnUserTaskCandidateStrategyOptions
        },
        getBpmnModelFormTypeOptions(): BpmnOption[] {
          return this.bpmnModelFormTypeOptions
        },
        getBpmnModelTypeOptions(): BpmnOption[] {
          return this.bpmnModelTypeOptions
        },
        getBpmnProcessListenerTypeOptions(): BpmnOption[] {
          return this.bpmnProcessListenerTypeOptions
        },
        getBpmnProcessListenerValueTypeOptionss(): BpmnOption[] {
          return this.bpmnProcessListenerValueTypeOptions
        },
        isInitialized():boolean{
            return this.initialized;
        }
    },

    actions: {

        setTitle(title: string, path?: string) {
          
        },
        async init() {
            if (!this.initialized) {
                // 这里可以执行初始化逻辑
                const data = (await API_BPMN_ENUM.getAllBpmnEnum()).data
                
                if(data[BpmnEnumDataKey.BPMN_USER_TASK_CANDIDATE_STRATEGY]){
                    this.bpmnUserTaskCandidateStrategyOptions = data[BpmnEnumDataKey.BPMN_USER_TASK_CANDIDATE_STRATEGY];
                }
                if(data[BpmnEnumDataKey.BPMN_MODEL_TYPE]){
                    this.bpmnModelTypeOptions = data[BpmnEnumDataKey.BPMN_MODEL_TYPE];
                }
                if(data[BpmnEnumDataKey.BPMN_MODEL_FORM_TYPE]){
                    this.bpmnModelFormTypeOptions = data[BpmnEnumDataKey.BPMN_MODEL_FORM_TYPE];
                }
                if(data[BpmnEnumDataKey.BPMN_PROCESS_LISTENER_TYPE]){
                    this.bpmnProcessListenerTypeOptions = data[BpmnEnumDataKey.BPMN_PROCESS_LISTENER_TYPE];
                }
                if(data[BpmnEnumDataKey.BPMN_PROCESS_LISTENER_VALUE_TYPE]){
                    this.bpmnProcessListenerValueTypeOptions = data[BpmnEnumDataKey.BPMN_PROCESS_LISTENER_VALUE_TYPE];
                }

                
                this.initialized = true
            }
        }

      
    }
  })

export default useBpmnEnumStore
